package com.larissa.quiz;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;

import androidx.fragment.app.Fragment;

public class SingleQuestionFragment extends Fragment {
    private static final String TAG="SingleQuestionFragment";
    private Question question;


    @Override
    public void onAttach(Context context){
        super.onAttach(getContext());
        Log.d(TAG,"onAttach() called");
    }

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Log.d(TAG,"onCreate() called");
        String text=SingleQuestionFragmentArgs.fromBundle(getArguments()).getQuestionText();
        Boolean answer=SingleQuestionFragmentArgs.fromBundle(getArguments()).getQuestionAnswer();
        question=new Question(text,answer);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        super.onCreateView(inflater,container,savedInstanceState);
        Log.d(TAG,"onCreateView() called");
        View view=inflater.inflate(R.layout.fragment_single_question,container,false);
        ((EditText)view.findViewById(R.id.question_title)).setText(question.getQuestionText());

        if(question.isQuestionAnswer())
            ((CheckBox)view.findViewById(R.id.ckb_true)).setChecked(true);
        else
            ((CheckBox)view.findViewById(R.id.ckb_false)).setChecked(true);
        return view;
    }

    @Override
    public void onDestroyView(){
        super.onDestroyView();
        Log.d(TAG,"onDestroyView() called");
    }
    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d(TAG,"onDestroy() called");
    }

    @Override
    public void onDetach(){
        super.onDetach();
        Log.d(TAG,"onDetach() called");
    }
}
